﻿module FlexSelectConfig {
	"use strict";
	interface IConfiguration {
		templateType: TemplateType; // (default: div)
		template: ITemplate; // (default: see template)
		mode: Mode; // (default: ReadOnly)
		search: ISearch; // how to act when typing (default: see ISearchBehaviour)
		hideSelected: boolean; // if true the selection value is not shown in options (default: false)
		required: boolean; // is the model invalid when nothing is selected (default: false)
		emptyValue: any; // value of the model when deselecting (default: null)
		allowEmpty: boolean; // is the value from emptyValue a valid value (default: true)
		autoSelectFirst: boolean; // when model is not valid and allow empty is false select first valid option (default: false)
		dataType: DataType; // what type off data are we handling (default: objects)
		sort: string; // only for dataType object. Angular sort value. Empty string preserves sort of input. (default: "")
		leigthWeight: boolean; // less features better performance (default: false)
		hooks: IHooks; // the hooks/API for events to listen to or override (default: ??? )
		jsonSource?: IJsonSource; // when set the data will be pulled from this source instead of the items attribute
	}

	interface IJsonSource {
		dataUrl: string; // search-string is appended to the end of url. (default: not set)
		preLoad: boolean; // indicates if a blank search is done on startup. (default: true)
		initialSearchLength: number; // number of letters to type before searching. blank will always trigger search. (default: 0)
		initialSearchDelay: number; // number of miliseconds to wait after last type before searching. (default: 100)
	}

	interface ITemplate {
		container: String;
		topLevelClass: String;
		element: String;
		elementHeader: String;
		displayFields: string[]; // only for dataType object and building templates. The properties to show in list and selected value.
	}

	interface ISearch {
		resultBehaviour: ResultBehaviour; // show to show results (default: Limit)
		// keyField: string; // only for dataType object. The property to use at key. Empty string will
		searchFields: string[]; // only for dataType object. The property/properties to use search when typing
		mode: SearchMode; // how to search. Full is full sentence, SplitAnd/SplitOr splits by space " " and use and/or logic (default: Full)
	}

	interface IHooks {
		selected: IValueFunc;
	}

	enum TemplateType { Select, Table, Div, Custom, PartialSelect, PartialTable, PartialDiv };
	enum Mode { ReadOnly, Edit, Add }
	enum ResultBehaviour { Limit, HighLight }
	enum DataType { numbers, strings, objects }
	enum SearchMode { Full, SplitAnd, SplitOr }

	/* Trigger/hook functions */
	interface IValueFunc { (value: any): void; }
	interface IVoidFunc { (): void;}
}